// pages/cvFeedback/cvFeedback.js
const db = wx.cloud.database({
    env: 'work1-0g1b3grp436e9236'
})

Page({

    /**
     * 页面的初始数据
     */
    data: {
        isNull: false,
        jobList: [],
        loading: true,
        curPage: 0
    },

    toCvStaDetailsPage(e) {
        const postId = e.currentTarget.dataset.id
        wx.navigateTo({url: '/pages/cvStaDetails/cvStaDetails?id=' + postId})
    },

    async getJobList(limit = 10) {
        const userInfo = wx.getStorageSync('userInfo')
        let res = await db.collection('work_post').skip(this.data.curPage * limit).limit(limit)
                .where({
                    userId: userInfo.userId
                }).orderBy('status', 'desc').orderBy('salary', 'desc').get()
        let jobList = res.data
        this.setData({
            jobList: this.data.jobList.concat(jobList),
            loading: false
        })
        if (this.data.jobList.length === 0) {
            this.setData({isNull: true})
        }
        // console.log(jobList)
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getJobList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    async onPullDownRefresh() {
        wx.showNavigationBarLoading()
        this.setData({
            jobList: [],
            curPage: 0,
            loading: true
        })
        await this.getJobList()
        wx.hideNavigationBarLoading()
        // 数据成功后，停止下拉刷新
        wx.stopPullDownRefresh()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        wx.showLoading({
            title: '加载中..',
        })
        this.setData({
            curPage: this.data.curPage + 1
        })
        this.getJobList().then(() => {
            // 数据成功后，停止下拉刷新
            wx.stopPullDownRefresh()
            wx.hideLoading()
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})